package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsyCropEvent;
import com.ruoyi.ncpsy.service.INcpsyCropEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作物事件记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/ncpsy/event")
public class NcpsyCropEventController extends BaseController
{
    @Autowired
    private INcpsyCropEventService ncpsyCropEventService;

    /**
     * 查询作物事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcpsyCropEvent ncpsyCropEvent)
    {
        startPage();
        List<NcpsyCropEvent> list = ncpsyCropEventService.selectNcpsyCropEventList(ncpsyCropEvent);
        return getDataTable(list);
    }

    /**
     * 导出作物事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:event:export')")
    @Log(title = "作物事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsyCropEvent ncpsyCropEvent)
    {
        List<NcpsyCropEvent> list = ncpsyCropEventService.selectNcpsyCropEventList(ncpsyCropEvent);
        ExcelUtil<NcpsyCropEvent> util = new ExcelUtil<NcpsyCropEvent>(NcpsyCropEvent.class);
        util.exportExcel(response, list, "作物事件记录数据");
    }

    /**
     * 获取作物事件记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:event:query')")
    @GetMapping(value = "/{cropEventId}")
    public AjaxResult getInfo(@PathVariable("cropEventId") Long cropEventId)
    {
        return success(ncpsyCropEventService.selectNcpsyCropEventByCropEventId(cropEventId));
    }

    /**
     * 新增作物事件记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:event:add')")
    @Log(title = "作物事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsyCropEvent ncpsyCropEvent)
    {
        return toAjax(ncpsyCropEventService.insertNcpsyCropEvent(ncpsyCropEvent));
    }

    /**
     * 修改作物事件记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:event:edit')")
    @Log(title = "作物事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsyCropEvent ncpsyCropEvent)
    {
        return toAjax(ncpsyCropEventService.updateNcpsyCropEvent(ncpsyCropEvent));
    }

    /**
     * 删除作物事件记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:event:remove')")
    @Log(title = "作物事件记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cropEventIds}")
    public AjaxResult remove(@PathVariable Long[] cropEventIds)
    {
        return toAjax(ncpsyCropEventService.deleteNcpsyCropEventByCropEventIds(cropEventIds));
    }
}
